const { getProjectListData, removeProjectData, createProjectData, updateProjectData, getProjectData } = require("../service/project-service")

class ProjectController {
  // 获取项目列表
  async getProjectList(ctx, next) {
    ctx.body = await getProjectListData()
  }
  // 获取单个项目
  async getProject(ctx, next) {
    const { projectId } = ctx.request.params
    ctx.body = await getProjectData(projectId)
  }
  // 根据id删除项目
  async removeProject(ctx, next) {
    const { projectId } = ctx.request.params
    ctx.body = await removeProjectData(projectId)
  }
  // 创建项目
  async createProject(ctx, next) {
    const { name, sourceUrl, onlineUrl, introduce } = ctx.request.body
    ctx.body = await createProjectData(name, sourceUrl, onlineUrl, introduce)
  }
  // 更新项目
  async updateProject(ctx, next) {
    const { name, sourceUrl, onlineUrl, introduce } = ctx.request.body
    const { projectId } = ctx.request.params
    ctx.body = await updateProjectData(projectId, { name, sourceUrl, onlineUrl, introduce })
  }
}

module.exports = new ProjectController()